package cn.xuexiluxian.open.admin.controller.system;

import cn.hutool.core.util.StrUtil;
import cn.xuexiluxian.open.common.enums.ResultStatusCodeEnum;
import cn.xuexiluxian.open.common.response.ResponseResult;
import cn.xuexiluxian.open.system.model.entity.SystemArea;
import cn.xuexiluxian.open.system.service.ISystemAreaService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("system/area")
public class SystemAreaController {
    @Autowired
    private ISystemAreaService systemAreaService;

    @GetMapping("getAreaByParentId")
    public ResponseResult getAreaByParentId(Integer parentId){
        if(parentId == null || StrUtil.isBlank(parentId + "")){
            return ResponseResult.error(ResultStatusCodeEnum.PARAM_REQUIRE_ERROR);
        }
        List<SystemArea> list = systemAreaService.selectListByParentId(parentId);
        return ResponseResult.ok(list);
    }

    @GetMapping("getAreaById")
    public ResponseResult getAreaById(Integer id){
        if(id == null || StringUtils.isBlank(id + "")){
            return ResponseResult.error(ResultStatusCodeEnum.PARAM_REQUIRE_ERROR);
        }
        SystemArea area = systemAreaService.getById(id);
        return ResponseResult.ok(area);
    }

}
